package com.yanqu.road.server.cmd.activity.lanyamemorial;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LangYaMemorialProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.langyamemorial.LangYaMemorialMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_LANGYA_MEMORIAL_ATTIC_GET, desc = "阁子列表")
public class LangYaMemorialAtticListCmd extends AbstractCommand {

    LangYaMemorialProto.LangYaMemorialAtticListReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = LangYaMemorialProto.LangYaMemorialAtticListReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        // 没有活动
        if (!ActivityMgr.activityInShowTime(LangYaMemorialMgr.getActivityInfo()) || LangYaMemorialMgr.getConfig() == null) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        if(reqMsg.getPage() <= 0 || reqMsg.getPageSize() > 500){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }

        LangYaMemorialProto.CrossLangYaMemorialAtticListReqMsg.Builder crossReq = LangYaMemorialProto.CrossLangYaMemorialAtticListReqMsg.newBuilder();
        crossReq.setActivityId(LangYaMemorialMgr.getActivityId());
        crossReq.setPage(reqMsg.getPage());
        crossReq.setPageSize(reqMsg.getPageSize());
        player.sendPacket(Protocol.C_LANGYA_MEMORIAL_ATTIC_GET, crossReq);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            LangYaMemorialProto.LangYaMemorialAtticListRespMsg.Builder builder = LangYaMemorialProto.LangYaMemorialAtticListRespMsg.newBuilder();
            builder.setRet(ret);
            builder.setPage(reqMsg.getPage());
            builder.setPageSize(reqMsg.getPageSize());
            player.sendPacket(Protocol.U_LANGYA_MEMORIAL_ATTIC_GET, builder);
        }
    }
}
